{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import torch\n",
    "import random\n",
    "import torch.nn as nn\n",
    "import numpy as np\n",
    "\n",
    "def seed_torch(seed=1029):\n",
    "\trandom.seed(seed)\n",
    "\tos.environ['PYTHONHASHSEED'] = str(seed) # 为了禁止hash随机化，使得实验可复现\n",
    "\tnp.random.seed(seed)\n",
    "\ttorch.manual_seed(seed)\n",
    "\ttorch.cuda.manual_seed(seed)\n",
    "\ttorch.cuda.manual_seed_all(seed) # if you are using multi-GPU.\n",
    "\ttorch.backends.cudnn.benchmark = False\n",
    "\ttorch.backends.cudnn.deterministic = True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([1, 1, 7, 7])\n",
      "tensor([[[[ 0.0041,  0.2263,  0.2715,  0.2263,  0.2715,  0.2263,  0.2673],\n",
      "          [-0.2780,  0.1405,  0.0198,  0.1405,  0.0198,  0.1405,  0.2978],\n",
      "          [-0.0739,  0.0092, -0.1363,  0.0092, -0.1363,  0.0092, -0.0624],\n",
      "          [-0.2780,  0.1405,  0.0198,  0.1405,  0.0198,  0.1405,  0.2978],\n",
      "          [-0.0739,  0.0092, -0.1363,  0.0092, -0.1363,  0.0092, -0.0624],\n",
      "          [-0.2780,  0.1405,  0.0198,  0.1405,  0.0198,  0.1405,  0.2978],\n",
      "          [-0.0781, -0.2171, -0.4078, -0.2171, -0.4078, -0.2171, -0.3297]]]],\n",
      "       grad_fn=<SlowConvTranspose2DBackward>)\n"
     ]
    }
   ],
   "source": [
    "seed_torch()\n",
    "input = torch.ones(1,1,3,3)\n",
    "m = nn.ConvTranspose2d(1, 1, kernel_size=3, stride=2, padding=0, output_padding=0,bias=False)\n",
    "y = m(input)\n",
    "print(y.shape)\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([1, 1, 5, 5])\n",
      "tensor([[[[ 0.1405,  0.0198,  0.1405,  0.0198,  0.1405],\n",
      "          [ 0.0092, -0.1363,  0.0092, -0.1363,  0.0092],\n",
      "          [ 0.1405,  0.0198,  0.1405,  0.0198,  0.1405],\n",
      "          [ 0.0092, -0.1363,  0.0092, -0.1363,  0.0092],\n",
      "          [ 0.1405,  0.0198,  0.1405,  0.0198,  0.1405]]]],\n",
      "       grad_fn=<SlowConvTranspose2DBackward>)\n"
     ]
    }
   ],
   "source": [
    "seed_torch()\n",
    "m = nn.ConvTranspose2d(1, 1, kernel_size=3, stride=2, padding=1, output_padding=0,bias=False)\n",
    "y = m(input)\n",
    "print(y.shape)\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([1, 1, 6, 6])\n",
      "tensor([[[[ 0.1405,  0.0198,  0.1405,  0.0198,  0.1405,  0.2978],\n",
      "          [ 0.0092, -0.1363,  0.0092, -0.1363,  0.0092, -0.0624],\n",
      "          [ 0.1405,  0.0198,  0.1405,  0.0198,  0.1405,  0.2978],\n",
      "          [ 0.0092, -0.1363,  0.0092, -0.1363,  0.0092, -0.0624],\n",
      "          [ 0.1405,  0.0198,  0.1405,  0.0198,  0.1405,  0.2978],\n",
      "          [-0.2171, -0.4078, -0.2171, -0.4078, -0.2171, -0.3297]]]],\n",
      "       grad_fn=<SlowConvTranspose2DBackward>)\n"
     ]
    }
   ],
   "source": [
    "seed_torch()\n",
    "m = nn.ConvTranspose2d(1, 1, kernel_size=3, stride=2, padding=1, output_padding=1,bias=False)\n",
    "y = m(input)\n",
    "print(y.shape)\n",
    "print(y)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
